package com.huiminpay.paymentagent.message;

import com.alibaba.fastjson.JSONObject;
import com.huiminpay.paymentagent.api.conf.AliConfigParam;
import com.huiminpay.paymentagent.api.dto.PaymentResponseDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class PayProducer {
    private static final String TOPIC_ORDER = "TP_PAYMENT_ORDER";
    private static final String TOPIC_RESULT = "TP_PAYMENT_RESULT";
    @Resource
    public RocketMQTemplate rocketMQTemplate;
    public void  payOrderNotice(PaymentResponseDTO<AliConfigParam> result) {
        //查询结果发送延误消息
        Message<PaymentResponseDTO<AliConfigParam>> notice = MessageBuilder.withPayload(result).build();
        rocketMQTemplate.syncSend(TOPIC_ORDER,notice,3000,3);
        log.info("[代理服务查询支付结果]:{}", JSONObject.toJSONString(result));
    }
    //发送结果消息
    public void payResultNotice(PaymentResponseDTO<?> result){
        rocketMQTemplate.convertAndSend(TOPIC_RESULT,result);
        log.info("[代理服务查询支付结果]:{}", JSONObject.toJSONString(result));
    }
}
